<template>
  <div id="user-address">
    <Header goback="true" headerTitle="编辑地址">
      <span slot="update" class="update-nav" @click="deleteAddress">{{
        deteleOrcomplete
      }}</span>
    </Header>
    <div class="address-content">
      <div v-if="addressList && addressList.length > 0" class="address-history">
        <div v-for="(item, index) in addressList" class="history-item">
          <p>{{ item.detailsAddress }}</p>
          <p>{{ item.tel }}</p>
          <span
            class="iconfont icon-shanchu delete-icon"
            v-if="!deleteicon"
            @click="deleteHistoryItem(index)"
          ></span>
        </div>
      </div>
      <div>
        <router-link to="/user/info/address/add" class="add-address">
          <p>新增地址</p>
          <span class="iconfont icon-xiangyou1"></span>
        </router-link>
      </div>
    </div>
    <div>
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import Header from "../../../../components/header/header";
export default {
  data() {
    return {
      deleteicon: true,
      deteleOrcomplete: "编辑",
      addressList: [
        {
          name: "15923648715",
          detailsAddress: "白云区",
          tel: "15923648715",
        },
        {
          name: "15923648715",
          detailsAddress: "白云区",
          tel: "15923648715",
        },
      ],
    };
  },
  components: { Header },
  methods: {
    deleteAddress() {
      if (this.deleteicon) {
        this.deteleOrcomplete = "完成";
        this.deleteicon = false;
      } else {
        this.deteleOrcomplete = "编辑";
        this.deleteicon = true;
      }
    },
    deleteHistoryItem(id) {
      this.addressList.splice(id, 1);
    },
  },
};
</script>

<style lang="scss" scoped>
//引入公告模块
@import "../../../../style/mixin";
#user-address {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  @include wh(100%, 100%);
  background: #f2f2f2;
}
.update-nav {
  @include ct;
  right: 0.3rem;
  @include sc(0.7rem, #fff);
}

.address-content {
  padding-top: 1.95rem;
  @include wh(100%, 100%);
}

.address-history {
  margin-top: 0.3rem;
  border-bottom: 0.05rem solid #dddddd;
  .history-item {
    background: white;
    padding: 0 0.4rem;
    border-top: 0.05rem solid #dddddd;
    padding-bottom: 0.4rem;
    position: relative;
  }
  p {
    @include sc(0.6rem, black);
    padding-top: 0.4rem;
  }
  p:last-child {
    padding-top: 0.2rem;
  }
}
.delete-icon {
  // position: absolute;
  @include ct;
  right: 0.5rem;
  @include sc(0.75rem, #666666);
}
.add-address {
  display: block;
  @include fj;
  align-items: center;
  height: 2rem;
  padding: 0 0.4rem;
  background: white;
  margin-top: 0.5rem;
  border-top: 0.05rem solid #dddddd;
  border-bottom: 0.05rem solid #dddddd;
  p {
    font-size: 0.6rem;
  }
  span {
    @include sc(0.75rem, #dddddd);
  }
}
</style>
